package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/10 12:31
 **/
public class Day25_2_Num31_NextPermutation {
    class Solution {
        public void nextPermutation(int[] nums) {
            for(int i = nums.length-2;i > 0;i--){
                if(nums[i] < nums[nums.length-1]){
                    int temp = nums[i];
                    nums[i] = nums[nums.length-1];
                    nums[nums.length-1] = temp;
                    return;
                }
            }
            int n = nums.length;
            while(n-- >0){
                int temp = nums[0];
                for(int i = 1;i < nums.length-1;i++){
                    nums[i] = nums[i+1];
                }
                nums[nums.length-1] = temp;
            }
            return;
        }
    }
}